package cn.wenhe9.yygh.hosp.controller.api;

import cn.wenhe9.yygh.common.result.ResultResponse;
import cn.wenhe9.yygh.hosp.service.DepartmentService;
import cn.wenhe9.yygh.hosp.service.HospitalService;
import cn.wenhe9.yygh.hosp.service.HospitalSetService;
import cn.wenhe9.yygh.hosp.service.ScheduleService;
import cn.wenhe9.yygh.model.hosp.Schedule;
import cn.wenhe9.yygh.model.vo.hosp.HospitalQueryVo;
import cn.wenhe9.yygh.model.vo.hosp.ScheduleOrderVo;
import cn.wenhe9.yygh.model.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author DuJinliang
 * 2022/4/3
 */
@Api(tags = "前台医院数据接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Resource
    private HospitalService hospitalService;

    @Resource
    private HospitalSetService hospitalSetService;

    @Resource
    private DepartmentService departmentService;

    @Resource
    private ScheduleService scheduleService;


    /**
     * 多条件、分页查询医院列表
     * @param page Integer
     * @param limit Integer
     * @param hospitalQueryVo HospitalQueryVo
     * @return ResultResponse
     */
    @ApiOperation("查询医院列表")
    @GetMapping("/{page}/{limit}")
    public ResultResponse findHospitalList(
        @PathVariable(name = "page") Integer page,
        @PathVariable(name = "limit") Integer limit,
        HospitalQueryVo hospitalQueryVo
    ){
        return hospitalService.findHospitalsByPage(hospitalQueryVo, page, limit);
    }

    /**
     * 根据医院名称查询
     * @param hosname String
     * @return ResultResponse
     */
    @ApiOperation("根据医院名称查询")
    @GetMapping("/hosname/{hosname}")
    public ResultResponse findByHosname(@PathVariable(name = "hosname") String hosname){
        return hospitalService.findByHosname(hosname);
    }

    /**
     * 根据医院编号获取科室
     * @param hoscode String
     * @return ResultResponse
     */
    @ApiOperation("根据医院编号获取科室")
    @GetMapping("/department/{hoscode}")
    public ResultResponse findDepartmentList(@PathVariable(name = "hoscode") String hoscode){
        return departmentService.findDeptTree(hoscode);
    }

    /**
     * 根据医院编号获取医院预约挂号详情
     * @param hoscode String
     * @return ResultResponse
     */
    @ApiOperation("根据医院编号获取医院预约挂号详情")
    @GetMapping("/hoscode/{hoscode}")
    public ResultResponse getScheduleDetail(@PathVariable(name = "hoscode") String hoscode){
        return hospitalService.findHospDetail(hoscode);
    }

    /**
     * 获取可预约的排班数据
     * @param page Integer
     * @param limit Integer
     * @param hoscode String
     * @param depcode String
     * @return ResultResponse
     */
    @ApiOperation("获取可预约的排班数据")
    @GetMapping("/auth/bookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public ResultResponse getBookingSchedule(
            @PathVariable(name = "page") Integer page,
            @PathVariable(name = "limit") Integer limit,
            @PathVariable(name = "hoscode") String hoscode,
            @PathVariable(name = "depcode") String depcode
    ){
        return scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
    }

    /**
     * 获取排班数据
     * @param hoscode String
     * @param depcode String
     * @param workDate String
     * @return ResultResponse
     */
    @ApiOperation("获取排班数据")
    @GetMapping("/auth/scheduleList/{hoscode}/{depcode}/{workDate}")
    public ResultResponse getScheduleList(
            @PathVariable(name = "hoscode") String hoscode,
            @PathVariable(name = "depcode") String depcode,
            @PathVariable(name = "workDate") String workDate
    ){
        return scheduleService.getDetailSchedule(hoscode, depcode, workDate);
    }


    /**
     * 根据排班id获取排班数据
     * @param scheduleId String
     * @return ResultResponse
     */
    @ApiOperation("根据排班id获取排班数据")
    @GetMapping("/auth/schedule/{scheduleId}")
    public ResultResponse getScheduleById(@PathVariable(name = "scheduleId") String scheduleId){
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        if (schedule == null){
            return ResultResponse.fail();
        }
        return ResultResponse.ok(schedule);
    }

    /**
     * 根据排班id获取预约下单数据
     * @param scheduleId String
     * @return ScheduleOrderVo
     */
    @ApiOperation("根据排班id获取预约下单数据")
    @GetMapping("/inner/scheduleOrder/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable(name = "scheduleId") String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    /**
     * 获取医院签名信息
     * @param hoscode String
     * @return SignInfoVo
     */
    @ApiOperation("获取医院签名信息")
    @GetMapping("/inner/signInfo/{hoscode}")
    public SignInfoVo getSignInfo(@PathVariable(name = "hoscode") String hoscode){
        return hospitalSetService.getSignInfo(hoscode);
    }
}
